package cn.wolfcode.web.controller;


import cn.wolfcode.domain.Log;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ILogService;
import cn.wolfcode.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/log")
public class LogController {

    @Autowired
    private ILogService logService;


    @RequiredPermission(name="日志页面",expression="log:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
//        PageInfo<Log> pageInfo = logService.query(qo);
//        model.addAttribute("pageInfo", pageInfo);
        return "log/list";
}


    @RequiredPermission(name="日志删除",expression="log:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           logService.delete(id);
        }
        return "redirect:/log/list";
    }


    @RequiredPermission(name="日志新增/编辑",expression="log:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Log log) {
        if (log.getId() == null) {
            logService.save(log);
        } else {
            logService.update(log);
        }
        return "redirect:/log/list";
    }


    @RequiredPermission(name="日志新增/编辑",expression="log:saveOrUpdate")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("log",logService.get(id));
        }
        return "log/input";
    }
}
